package com.itmeima.text3;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Demo1 {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
       Student s = new Student("张三",23);


        Object o = getProperty(s, "name");

        System.out.println(o);

    }

    public static Object getProperty(Object obj, String propertyName) throws IllegalAccessException, NoSuchFieldException {
        Class<?> aClass = obj.getClass();

        Field declaredField = aClass.getDeclaredField(propertyName);

        declaredField.setAccessible(true);

        Object o = declaredField.get(obj);

        return o;
    }
}